<?php

namespace paper\http\response;

class ViewResponse extends Response
{

    protected string $contentType = 'text/html';
    protected array $vars = [];

    public function __construct($data = '', int $code = 200, array $header = [], $parameters = null)
    {
        parent::__construct($data, $code, $header, $parameters);
    }

    /**
     * @param array $vars
     */
    public function setVars(array &$vars): static
    {
        $this->vars = &$vars;
        return $this;
    }

    /**
     * @param  $data mixed 模板路径
     * @return string
     * @throws \paper\exception\HttpException
     */
    protected function output($data): string
    {
        $view = view();
        $view->setViewPath(PAPER_APP_PATH . '/view/');
        return $view->render($data, $this->vars);
    }

    protected function contentType(): string
    {
        return 'text/html';
    }
}